package com.tanhua.dubbo.server.api;

import com.alibaba.dubbo.config.annotation.Service;
import com.tanhua.dubbo.server.pojo.UserLocation;
import com.tanhua.dubbo.server.vo.UserLocationVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;



/**
 * @author why
 */
@Service(version = "1.0.0")
public class UserLocationApiImpl implements UserLocationApi1 {

    @Autowired
    private MongoTemplate mongoTemplate;

    /**
     * 根据用户id查询现在的位置
     * @param userId
     * @return
     */
    @Override
    public UserLocationVo queryByUserId(Long userId) {

        Query query=Query.query(Criteria.where("userId").is(userId));
        UserLocation userLocation = this.mongoTemplate.findOne(query, UserLocation.class);
        if (userLocation!=null){
            UserLocationVo format = UserLocationVo.format(userLocation);
            return format;
        }

        return null;
    }



}
